package com.houtai.service.activity.apply;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houtai.base.RetInfo;
import com.houtai.bean.TdActivityApply;
import com.houtai.bean.dto.activity.apply.PageActivityApply;
import com.houtai.common.util.LogUtils;
import com.houtai.dao.TdActivityApplyDao;
import com.houtai.dao.TsJzAdminOperationDao;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lizhun on 2017/7/28.
 */
@Service

public class ActivityApplyService {
    private static Logger logger = Logger.getLogger(ActivityApplyService.class);

    @Autowired
    private TdActivityApplyDao tdActivityApplyDao;


    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private TsJzAdminOperationDao tsJzAdminOperationDao;

    /**
     * @Purpose   查找活动报名列表
     * @param     page
     * @version   1.0
     * @author    李准
     * @time      2017-08-19
     * @return    RetInfo
     */
    public RetInfo findTdActivityApply(PageActivityApply page, HttpServletRequest request) {
        String logInfo = this.getClass().getName() + ":findTdActivityApply:";
        RetInfo retInfo = new RetInfo();
        logger.info("======" + logInfo + "begin======");
        try {
            PageHelper.startPage(page.getCurrent_page(), page.getPage_size(), "apply_id desc");
            List<TdActivityApply> lists = tdActivityApplyDao.findTdActivityApply(page);
            PageInfo<TdActivityApply> list = new PageInfo<>(lists);
            Map<String, Object> map = new HashMap<>();
            map.put("list", list.getList());
            map.put("total_page", list.getPages());
            map.put("total_record", list.getTotal());
            map.put("current_page", list.getPageNum());
            map.put("page_size", list.getPageSize());
            map.put("activity_id", page.getActivity_id());

            retInfo.setMark("0");
            retInfo.setTip("成功");
            retInfo.setObj(map);
            LogUtils.AdminOperation(redisTemplate ,tsJzAdminOperationDao,"查找活动报名列表" , request);

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");

        return retInfo;
    }
    public List<TdActivityApply> findTdActivityApplyExport(PageActivityApply page) {
        return tdActivityApplyDao.findTdActivityApply(page);
    }
}
